﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using whatpricemyhouse.LINQ;

namespace whatpricemyhouse.Sell
{
    public partial class DetailedReportForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ImageButton1.Attributes.Add("onmouseover", "mouseOver1(this);");
            ImageButton1.Attributes.Add("onmouseout", "mouseOut1(this);");

            if (Session["areaName"] == null)
            {
                Response.Redirect("~/default.aspx?e=T");
            }
            else if (Session["areaName"].ToString() == "")
            {
                Response.Redirect("~/default.aspx?e=T");
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //--Custoemr ID
            String CustomerID = Guid.NewGuid().ToString();
            //-----save customer

            DataControllerDataContext dcdc = new DataControllerDataContext();


            customer_table ct = new customer_table();
            ct.CID = CustomerID;
            ct.CName = this.UserNameTxt.Text;
            ct.CEmail = this.UserEmailTxt.Text;
            ct.CPhone = this.UserPhoneTxt.Text;
            ct.CCreateDate = DateTime.Now;
            dcdc.customer_tables.InsertOnSubmit(ct);

            //--sell Request ID
            String SellRequestID = Guid.NewGuid().ToString();

            sell_request_table crt = new sell_request_table();
            crt.SRTID = SellRequestID;
            crt.ReportType = true;
            crt.Address = AddressTxt.Text;
            crt.suburbid = placeSelector.getSelectedValue();
            crt.YATTID = youAreTheSelector.getSelectedValue();
            crt.PTID = propertyTypeSelector.getSelectedValue();
            crt.BedroomsID = bedroomsSelector.getSelectedValue();
            crt.EnsuitesID = ensuitesSelector.getSelectedValue();
            crt.CarsID = carsSelector.getSelectedValue();
            crt.SectionSizeID = sectionSizeSelector.getSelectedValue();
            crt.SizeOfHomeID = sectionSizeSelector.getSelectedValue();
            crt.ConstructionID = constructionSelector.getSelectedValue();
            crt.ACTID = airConSelector.getSelectedValue();
            crt.PoolID = poolSelector.getSelectedValue();
            crt.Aspect = AspectTxt.Text;
            crt.Comments = CommentTxt.Text;
            crt.HFUTID = howFindUsSelector.getSelectedValue();
            crt.CID = CustomerID;
            crt.RatingID = ratingSelector.getSelectedValue();
            crt.isOld = true;
            crt.createDate = DateTime.Now;
            dcdc.sell_request_tables.InsertOnSubmit(crt);


            //save living room
            List<String> livingRoomCheckerList = livingRoomChecker.getCheckList();
            foreach (String v in livingRoomCheckerList)
            {
                sell_request__living_room_table srlrt = new sell_request__living_room_table();
                srlrt.SRTID = SellRequestID;
                srlrt.LRID = v;
                dcdc.sell_request__living_room_tables.InsertOnSubmit(srlrt);
            }

            List<String> OutsideAreaCheckerList = outsideAreaChecker.getCheckList();
            foreach (String v in OutsideAreaCheckerList) {
                out_side_area_sell_request_table osasrt = new out_side_area_sell_request_table();
                osasrt.SRTID = SellRequestID;
                osasrt.OATID = v;
                dcdc.out_side_area_sell_request_tables.InsertOnSubmit(osasrt);
            }

            //save loan type
            List<String> loanCheckList = loanTypeChecker.getCheckList();
            foreach (String v in loanCheckList)
            {
                sell_request__loan_type_table srltt = new sell_request__loan_type_table();
                srltt.SRTID = SellRequestID;
                srltt.LTID = v;
                dcdc.sell_request__loan_type_tables.InsertOnSubmit(srltt);
            }

            dcdc.SubmitChanges();

            Response.Redirect("~/PublicPage/ThankYou.aspx");
        }

    }
}